/*     */ package com.zimbra.cs.account.gal;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.Entry;
/*     */ import com.zimbra.cs.account.ldap.LdapGalCredential;
/*     */ import com.zimbra.cs.gal.GalSearchConfig;
/*     */ import com.zimbra.cs.gal.ZimbraGalSearchBase;
/*     */ import com.zimbra.cs.ldap.LdapConnType;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public abstract class GalParams
/*     */ {
/*     */   int mPageSize;
/*     */   String mTokenizeAutoCompleteKey;
/*     */   String mTokenizeSearchKey;
/*     */   
/*     */   GalParams(Entry ldapEntry, GalOp galOp)
/*     */     throws ServiceException
/*     */   {
/*  39 */     String pageSize = null;
/*  40 */     if (galOp == GalOp.sync) {
/*  41 */       pageSize = ldapEntry.getAttr("zimbraGalSyncLdapPageSize");
/*     */       
/*  43 */       if (pageSize == null)
/*  44 */         pageSize = ldapEntry.getAttr("zimbraGalLdapPageSize");
/*     */     } else {
/*  46 */       pageSize = ldapEntry.getAttr("zimbraGalLdapPageSize");
/*     */     }
/*     */     
/*  49 */     setPageSize(pageSize);
/*     */     
/*  51 */     this.mTokenizeAutoCompleteKey = ldapEntry.getAttr("zimbraGalTokenizeAutoCompleteKey");
/*  52 */     this.mTokenizeSearchKey = ldapEntry.getAttr("zimbraGalTokenizeSearchKey");
/*     */   }
/*     */   
/*     */   GalParams(Map attrs, GalOp galOp)
/*     */   {
/*  57 */     String pageSize = null;
/*  58 */     if (galOp == GalOp.sync) {
/*  59 */       pageSize = (String)attrs.get("zimbraGalSyncLdapPageSize");
/*     */       
/*  61 */       if (pageSize == null)
/*  62 */         pageSize = (String)attrs.get("zimbraGalLdapPageSize");
/*     */     } else {
/*  64 */       pageSize = (String)attrs.get("zimbraGalLdapPageSize");
/*     */     }
/*     */     
/*  67 */     setPageSize(pageSize);
/*     */     
/*  69 */     this.mTokenizeAutoCompleteKey = ((String)attrs.get("zimbraGalTokenizeAutoCompleteKey"));
/*  70 */     this.mTokenizeSearchKey = ((String)attrs.get("zimbraGalTokenizeSearchKey"));
/*     */   }
/*     */   
/*     */   private void setPageSize(String pageSize) {
/*  74 */     if (pageSize == null) {
/*  75 */       pageSize = "1000";
/*     */     }
/*     */     try {
/*  78 */       this.mPageSize = Integer.parseInt(pageSize);
/*     */     } catch (NumberFormatException e) {
/*  80 */       this.mPageSize = 0;
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*  85 */   public int pageSize() { return this.mPageSize; }
/*  86 */   public String tokenizeAutoCompleteKey() { return this.mTokenizeAutoCompleteKey; }
/*  87 */   public String tokenizeSearchKey() { return this.mTokenizeSearchKey; }
/*     */   
/*     */   public static class ZimbraGalParams
/*     */     extends GalParams
/*     */   {
/*     */     String mSearchBase;
/*     */     
/*     */     public ZimbraGalParams(Domain domain, GalOp galOp)
/*     */       throws ServiceException
/*     */     {
/*  97 */       super(galOp);
/*  98 */       this.mSearchBase = ZimbraGalSearchBase.getSearchBase(domain, galOp);
/*     */     }
/*     */     
/* 101 */     public String searchBase() { return this.mSearchBase; }
/*     */   }
/*     */   
/*     */   public static class ExternalGalParams extends GalParams {
/*     */     String[] mUrl;
/*     */     boolean mRequireStartTLS;
/*     */     String mSearchBase;
/*     */     String mFilter;
/*     */     LdapGalCredential mCredential;
/*     */     
/*     */     public ExternalGalParams(Entry ldapEntry, GalOp galOp) throws ServiceException {
/* 112 */       super(galOp);
/*     */       
/*     */       String startTlsEnabled;
/*     */       
/*     */       String authMech;
/*     */       String bindDn;
/*     */       String bindPassword;
/*     */       String krb5Principal;
/*     */       String krb5Keytab;
/* 121 */       if (galOp == GalOp.sync) {
/* 122 */         this.mUrl = ldapEntry.getMultiAttr("zimbraGalSyncLdapURL");
/* 123 */         this.mSearchBase = ldapEntry.getAttr("zimbraGalSyncLdapSearchBase");
/* 124 */         this.mFilter = ldapEntry.getAttr("zimbraGalSyncLdapFilter");
/*     */         
/* 126 */         String startTlsEnabled = ldapEntry.getAttr("zimbraGalSyncLdapStartTlsEnabled");
/* 127 */         String authMech = ldapEntry.getAttr("zimbraGalSyncLdapAuthMech");
/* 128 */         String bindDn = ldapEntry.getAttr("zimbraGalSyncLdapBindDn");
/* 129 */         String bindPassword = ldapEntry.getAttr("zimbraGalSyncLdapBindPassword");
/* 130 */         String krb5Principal = ldapEntry.getAttr("zimbraGalSyncLdapKerberos5Principal");
/* 131 */         String krb5Keytab = ldapEntry.getAttr("zimbraGalSyncLdapKerberos5Keytab");
/*     */         
/*     */ 
/* 134 */         if ((this.mUrl == null) || (this.mUrl.length == 0))
/* 135 */           this.mUrl = ldapEntry.getMultiAttr("zimbraGalLdapURL");
/* 136 */         if (this.mSearchBase == null)
/* 137 */           this.mSearchBase = ldapEntry.getAttr("zimbraGalLdapSearchBase", "");
/* 138 */         if (this.mFilter == null) {
/* 139 */           this.mFilter = ldapEntry.getAttr("zimbraGalLdapFilter");
/*     */         }
/* 141 */         if (startTlsEnabled == null)
/* 142 */           startTlsEnabled = ldapEntry.getAttr("zimbraGalLdapStartTlsEnabled");
/* 143 */         if (authMech == null)
/* 144 */           authMech = ldapEntry.getAttr("zimbraGalLdapAuthMech");
/* 145 */         if (bindDn == null)
/* 146 */           bindDn = ldapEntry.getAttr("zimbraGalLdapBindDn");
/* 147 */         if (bindPassword == null)
/* 148 */           bindPassword = ldapEntry.getAttr("zimbraGalLdapBindPassword");
/* 149 */         if (krb5Principal == null)
/* 150 */           krb5Principal = ldapEntry.getAttr("zimbraGalLdapKerberos5Principal");
/* 151 */         if (krb5Keytab == null) {
/* 152 */           krb5Keytab = ldapEntry.getAttr("zimbraGalLdapKerberos5Keytab");
/*     */         }
/*     */       } else {
/* 155 */         this.mUrl = ldapEntry.getMultiAttr("zimbraGalLdapURL");
/* 156 */         this.mSearchBase = ldapEntry.getAttr("zimbraGalLdapSearchBase", "");
/*     */         
/* 158 */         if (galOp == GalOp.autocomplete) {
/* 159 */           this.mFilter = ldapEntry.getAttr("zimbraGalAutoCompleteLdapFilter");
/*     */         } else {
/* 161 */           this.mFilter = ldapEntry.getAttr("zimbraGalLdapFilter");
/*     */         }
/* 163 */         startTlsEnabled = ldapEntry.getAttr("zimbraGalLdapStartTlsEnabled");
/* 164 */         authMech = ldapEntry.getAttr("zimbraGalLdapAuthMech");
/* 165 */         bindDn = ldapEntry.getAttr("zimbraGalLdapBindDn");
/* 166 */         bindPassword = ldapEntry.getAttr("zimbraGalLdapBindPassword");
/* 167 */         krb5Principal = ldapEntry.getAttr("zimbraGalLdapKerberos5Principal");
/* 168 */         krb5Keytab = ldapEntry.getAttr("zimbraGalLdapKerberos5Keytab");
/*     */       }
/*     */       
/* 171 */       boolean startTLS = startTlsEnabled == null ? false : "TRUE".equals(startTlsEnabled);
/* 172 */       this.mRequireStartTLS = LdapConnType.requireStartTLS(this.mUrl, startTLS);
/* 173 */       this.mCredential = new LdapGalCredential(authMech, bindDn, bindPassword, krb5Principal, krb5Keytab);
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */     public ExternalGalParams(Map attrs, GalOp galOp)
/*     */       throws ServiceException
/*     */     {
/* 183 */       super(galOp);
/*     */       
/*     */       String startTlsEnabled;
/*     */       
/*     */       String authMech;
/*     */       String bindDn;
/*     */       String bindPassword;
/*     */       String krb5Principal;
/*     */       String krb5Keytab;
/* 192 */       if (galOp == GalOp.sync) {
/* 193 */         this.mUrl = getMultiAttr(attrs, "zimbraGalSyncLdapURL", false);
/* 194 */         this.mSearchBase = ((String)attrs.get("zimbraGalSyncLdapSearchBase"));
/* 195 */         this.mFilter = ((String)attrs.get("zimbraGalSyncLdapFilter"));
/*     */         
/* 197 */         String startTlsEnabled = (String)attrs.get("zimbraGalSyncLdapStartTlsEnabled");
/* 198 */         String authMech = (String)attrs.get("zimbraGalSyncLdapAuthMech");
/* 199 */         String bindDn = (String)attrs.get("zimbraGalSyncLdapBindDn");
/* 200 */         String bindPassword = (String)attrs.get("zimbraGalSyncLdapBindPassword");
/* 201 */         String krb5Principal = (String)attrs.get("zimbraGalSyncLdapKerberos5Principal");
/* 202 */         String krb5Keytab = (String)attrs.get("zimbraGalSyncLdapKerberos5Keytab");
/*     */         
/*     */ 
/* 205 */         if ((this.mUrl == null) || (this.mUrl.length == 0))
/* 206 */           this.mUrl = getMultiAttr(attrs, "zimbraGalLdapURL", true);
/* 207 */         if (this.mSearchBase == null)
/* 208 */           this.mSearchBase = ((String)attrs.get("zimbraGalLdapSearchBase"));
/* 209 */         if (this.mFilter == null) {
/* 210 */           this.mFilter = getRequiredAttr(attrs, "zimbraGalLdapFilter");
/*     */         }
/* 212 */         if (startTlsEnabled == null)
/* 213 */           startTlsEnabled = (String)attrs.get("zimbraGalLdapStartTlsEnabled");
/* 214 */         if (authMech == null)
/* 215 */           authMech = (String)attrs.get("zimbraGalLdapAuthMech");
/* 216 */         if (bindDn == null)
/* 217 */           bindDn = (String)attrs.get("zimbraGalLdapBindDn");
/* 218 */         if (bindPassword == null)
/* 219 */           bindPassword = (String)attrs.get("zimbraGalLdapBindPassword");
/* 220 */         if (krb5Principal == null)
/* 221 */           krb5Principal = (String)attrs.get("zimbraGalLdapKerberos5Principal");
/* 222 */         if (krb5Keytab == null) {
/* 223 */           krb5Keytab = (String)attrs.get("zimbraGalLdapKerberos5Keytab");
/*     */         }
/*     */       } else {
/* 226 */         this.mUrl = getMultiAttr(attrs, "zimbraGalLdapURL", true);
/* 227 */         this.mSearchBase = ((String)attrs.get("zimbraGalLdapSearchBase"));
/*     */         
/* 229 */         if (galOp == GalOp.autocomplete) {
/* 230 */           this.mFilter = getRequiredAttr(attrs, "zimbraGalAutoCompleteLdapFilter");
/*     */         } else {
/* 232 */           this.mFilter = getRequiredAttr(attrs, "zimbraGalLdapFilter");
/*     */         }
/* 234 */         startTlsEnabled = (String)attrs.get("zimbraGalLdapStartTlsEnabled");
/* 235 */         authMech = (String)attrs.get("zimbraGalLdapAuthMech");
/* 236 */         bindDn = (String)attrs.get("zimbraGalLdapBindDn");
/* 237 */         bindPassword = (String)attrs.get("zimbraGalLdapBindPassword");
/* 238 */         krb5Principal = (String)attrs.get("zimbraGalLdapKerberos5Principal");
/* 239 */         krb5Keytab = (String)attrs.get("zimbraGalLdapKerberos5Keytab");
/*     */       }
/*     */       
/* 242 */       boolean startTLS = startTlsEnabled == null ? false : "TRUE".equals(startTlsEnabled);
/* 243 */       this.mRequireStartTLS = LdapConnType.requireStartTLS(this.mUrl, startTLS);
/* 244 */       this.mCredential = new LdapGalCredential(authMech, bindDn, bindPassword, krb5Principal, krb5Keytab);
/*     */     }
/*     */     
/*     */     private static String[] getMultiAttr(Map attrs, String name, boolean required) throws ServiceException {
/* 248 */       Object v = attrs.get(name);
/* 249 */       if ((v instanceof String)) return new String[] { (String)v };
/* 250 */       if ((v instanceof String[])) {
/* 251 */         String[] value = (String[])v;
/* 252 */         if ((value != null) && (value.length > 0))
/* 253 */           return value;
/*     */       }
/* 255 */       if (required) {
/* 256 */         throw ServiceException.INVALID_REQUEST("must specifiy: " + name, null);
/*     */       }
/* 258 */       return null;
/*     */     }
/*     */     
/*     */     private static String getRequiredAttr(Map attrs, String name) throws ServiceException {
/* 262 */       String value = (String)attrs.get(name);
/* 263 */       if (value == null)
/* 264 */         throw ServiceException.INVALID_REQUEST("must specifiy: " + name, null);
/* 265 */       return value;
/*     */     }
/*     */     
/* 268 */     public String[] url() { return this.mUrl; }
/* 269 */     public boolean requireStartTLS() { return this.mRequireStartTLS; }
/* 270 */     public String searchBase() { return GalSearchConfig.fixupExternalGalSearchBase(this.mSearchBase); }
/* 271 */     public String filter() { return this.mFilter; }
/* 272 */     public LdapGalCredential credential() { return this.mCredential; }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/gal/GalParams.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */